﻿using FluentValidation;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace NetCoreProject.Api.Infrastructure.Validator
{
    public class TokenModel : IValidatableObject
    {
        public string CorpID { get; set; }
        public string SecretKey { get; set; }
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            TokenModelValidator validator = new TokenModelValidator();
            var result =validator.Validate(this);
            return result.Errors.Select(u => new ValidationResult(u.ErrorMessage, new[] { u.PropertyName }));
        }
    }
    public class TokenModelValidator : AbstractValidator<TokenModel>
    {
        public TokenModelValidator()
        {
            RuleFor(x => x.CorpID).NotNull().NotEmpty(); 
            RuleFor(x => x.SecretKey).NotNull().NotEmpty();
        }
    }
}
